package com.yunyi.util;

import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @ClassName DateUtils
 * @Description 时间工具类
 * @Author leizhang
 * Date 2021/8/17 3:16 下午
 * @Version 1.0
 **/
public class DateUtil {
    /**当前时间后一天时间**/
    public static String getDayTimeAfter() {
        SimpleDateFormat format=new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return format.format(new Date());
    }

    public static long getOverTime() throws ParseException {
        long now = System.currentTimeMillis();
        SimpleDateFormat sdfOne = new SimpleDateFormat("yyyy-MM-dd");
        long overTime = (now - (sdfOne.parse(sdfOne.format(now)).getTime())) / 1000;
        return overTime;
    }

    /**日期计算
     */
    public static String dateSum(int threshold){
        SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");
        Date date = DateUtils.addDays(new Date(), threshold);
        return format.format(date);
    }

    /**日期计算
     */
    public static String getDayTime(){
        SimpleDateFormat format=new SimpleDateFormat("yyyyMMdd");
        return format.format(new Date());
    }

    //获取当天18点时间
    public static boolean getDateBefore_18(){
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 18);//控制时
        cal.set(Calendar.MINUTE, 0);//控制分
        cal.set(Calendar.SECOND, 0);//控制秒
        long time = cal.getTime().getTime();
        return time >  System.currentTimeMillis();
    }
    //redis 缓存时间点
    public static long getOverTime_24() throws ParseException {
        long now = System.currentTimeMillis();
        Date date = org.apache.commons.lang3.time.DateUtils.addHours(new Date(), 24);
        long time = date.getTime();
        return time-now;
    }

}
